<?php
/**
 * Created by PhpStorm.
 * User: zyark
 * Date: 2017/8/16
 * Time: 16:39
 */

namespace Admin\Logic;


use Common\Utils\Constants;
use Think\Exception;

class OrderLogic
{
    /**
     * 审核订单
     * @param $log_id int 记录id
     * @return int 0无法审核 1审核成功 2审核失败
     */
    public function verify($log_id){
        $model = M();
        $model->startTrans();
        $log =  $model->table('t_order')->where(array('id'=>$log_id))->find();
        if($log['verify'] != Constants::VERIFY_STATUS_IN){//审核中
            return 0;
        }
        try {
            $model->table('t_order')->where(array('id'=>$log_id))->setField('status', Constants::VERIFY_STATUS_SUCCESS);
            $model->commit();
            return 1;
        }catch (Exception $e){
            $model->rollback();
            return 2;
        }
    }

}